<?php

namespace App\Http\Controllers;

use App\Http\Resources\UserResource;
use App\Repositories\User\DB\UserDBRepository;
use App\Repositories\User\Filter\UserFilter;
use Illuminate\Http\Request;
use Log;

class DemoController extends Controller
{
    private $request;
    private $repository;

    public function __construct(Request $request, UserDBRepository $repository)
    {
        $this->request = $request;
        $this->repository = $repository;
    }

    /**
     * Controller-Route Demo
     * @api version:1.0
     * @method get
     * @return array
     */
    public function testGet()
    {
        $user = $this->getParam("user");
        return view('home')->with($user);
    }

    /**
     * 获取数据ORM Demo
     * @method get
     * @return \App\Library\Resources\Json\ResourceCollection
     */
    public function getPage()
    {
        $userFilter = new UserFilter($this->request);
        $paginator = $this->repository->getPaginator($userFilter);
        return UserResource::collection($paginator);
    }
}
